﻿@{
    ViewBag.Title = "现金银行报表";
    Layout = "~/Views/Shared/_ReportIndex.cshtml";
}
<script>
    $(function () {
        GetGrid();
    })
    function GetGrid() {
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../CustomerManage/CashBalanceReport/GetListJson",
            postData: { queryJson: JSON.stringify($("#filter-form").GetWebControls()) },
            datatype: "json",
            height: $(window).height() - 230.5,
            autowidth: true,
            colModel: [
                { label: "交易日期", name: "F_ExecutionDate", width: 100, align: 'left', sortable: true, formatter: "date", formatoptions: { newformat: 'Y-m-d' } },
                {
                    label: "交易账户", name: "F_CashAccount", width: 130, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clientdataItem["Client_PaymentAccount"][cellvalue];
                    }
                },
                {
                    label: "收入金额", name: "F_Receivable", width: 110, align: 'right',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return toDecimal(cellvalue);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    label: "支出金额", name: "F_Expenses", width: 110, align: 'right', formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return toDecimal(cellvalue);
                        } else {
                            return "";
                        }
                    }
                },
                { label: "账户余额", name: "F_Balance", width: 110, align: 'right', formatter: 'number', formatoptions: { thousandsSeparator: "", decimalPlaces: 2 } },
                {
                    label: '创建时间', name: 'F_CreateDate', index: 'F_CreateDate', width: 130, align: 'center',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i', newformat: 'Y-m-d H:i' }
                },
                { label: "摘要信息", name: "F_Abstract", width: 300, align: "left" }
            ],
            pager: false,
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            footerrow: true,
            gridComplete: function () {
                var totalreceivable = $(this).getCol("F_Receivable", false, "sum");
                var totalexpenses = $(this).getCol("F_Expenses", false, "sum");
                //合计
                $(this).footerData("set", {
                    "F_ExecutionDate": "合计：",
                    "F_Receivable": totalreceivable,
                    "F_Expenses": totalexpenses,
                });
                $('table.ui-jqgrid-ftable td').prevUntil().css("border-right-color", "#fff");
            }
        });
        //点击时间范围（今天、近7天、近一个月、近三个月）
        $("#time_horizon a.btn-default").click(function () {
            $("#time_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            switch ($(this).attr('data-value')) {
                case "1"://今天
                    $("#StartTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "2"://近7天
                    $("#StartTime").val("@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "3"://近一个月
                    $("#StartTime").val("@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                case "4"://近三个月
                    $("#StartTime").val("@DateTime.Now.AddMonths(-3).ToString("yyyy-MM-dd")");
                    $("#EndTime").val("@DateTime.Now.ToString("yyyy-MM-dd")");
                    break;
                default:
                    break;
            }
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
            $('#btn_Search').trigger("click");
        });
        //查询点击事件
        $("#btn_Search").click(function () {
            if (!$(".ui-filter-text").next('.ui-filter-list').is(":hidden")) {
                $(".ui-filter-text").trigger("click");
            }
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
            var queryJson = $("#filter-form").GetWebControls();
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
    }
    //打印
    function btn_print() {
        $("#gridPanel").printTable();
    }
    //导出
    function btn_export() {
        dialogOpen({
            id: "ExcelIExportDialog",
            title: '导出现金银行报表',
            url: '/Utility/ExcelExportForm?gridId=gridTable',
            width: "500px",
            height: "380px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }, btn: ['导出Excel', '关闭']
        });
    }
</script>
<div class="ui-report">
    <div class="titlePanel">
        <div class="title-search">
            <table>
                <tr>
                    <td>查询条件</td>
                    <td style="padding-left: 10px;">
                        <div class="ui-filter" style="width: 200px;">
                            <div class="ui-filter-text">
                                <strong id="SelectedStartTime">@DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.ToString("yyyy-MM-dd")</strong>
                            </div>
                            <div class="ui-filter-list" style="width: 350px;">
                                <table class="form" id="filter-form">
                                    <tr>
                                        <th class="formTitle">交易日期：</th>
                                        <td class="formValue">
                                            <input id="Category" type="hidden" value="1" />
                                            <div style="float: left; width: 45%;">
                                                <input id="StartTime" readonly type="text" value="@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                            </div>
                                            <div style="float: left; width: 10%; text-align: center;">至</div>
                                            <div style="float: left; width: 45%;">
                                                <input id="EndTime" readonly type="text" value="@LeaRun.Util.Time.GetToday()" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                <div class="ui-filter-list-bottom">
                                    <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                    <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td style="padding-left: 10px;">
                        <div id="time_horizon" class="btn-group">
                            <a class="btn btn-default" data-value="1">今天</a>
                            <a class="btn btn-default" data-value="2">近7天</a>
                            <a class="btn btn-default active" data-value="3">近1个月</a>
                            <a class="btn btn-default" data-value="4">近3个月</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="toolbar">
            <div class="btn-group">
                <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                <a id="lr-print" class="btn btn-default" onclick="btn_print()"><i class="fa fa-print"></i>&nbsp;打印</a>
                <a id="lr-export" class="btn btn-default" onclick="btn_export()"><i class="fa fa-sign-out"></i>&nbsp;导出</a>
            </div>
            <script>$('.toolbar').authorizeButton()</script>
        </div>
    </div>
    <div class="gridPanel" id="gridPanel">
        <div class="printArea">
            <div class="grid-title">现金银行报表</div>
            <div class="grid-subtitle">日期: 2016-03-10 至 2016-04-10</div>
            <table id="gridTable"></table>
        </div>
    </div>
</div>
